/*
 * The RavenX Library
 * Copyright (c) 2008 by Solidus
 * 
 * Permission to use, copy, modify, distribute and sell this software
 * and its documentation for any purpose is hereby granted without fee,
 * provided that the above copyright notice appear in all copies and
 * that both that copyright notice and this permission notice appear
 * in supporting documentation.It is provided "as is" without express 
 * or implied warranty.
 *
 */

#ifndef RX_LIST_H
#define RX_LIST_H

#include "rx_typedef.h"

RX_SPACE_BEG




typedef struct __rx_list_node_tag	rx_list_node_t;

typedef struct __rx_list_tag		rx_list_t;


RavenAPI void*			rx_list_node_data(rx_list_node_t *node);

RavenAPI rx_list_node_t* rx_list_node_next(const rx_list_t *self, rx_list_node_t *node);

RavenAPI rx_list_node_t* rx_list_node_prev(const rx_list_t *self, rx_list_node_t *node);


RavenAPI rx_list_node_t* rx_list_head(rx_list_t *self);

RavenAPI rx_list_node_t* rx_list_tail(rx_list_t *self);


RavenAPI rx_list_t*		rx_list_create(const rx_info_t *info, const rx_alloc_t *palloc);

RavenAPI void			rx_list_destroy(rx_list_t* self);

RavenAPI void			rx_list_clear(rx_list_t* self);

RavenAPI rx_list_t*		rx_list_copy(const rx_list_t* self);

RavenAPI rx_list_node_t* rx_list_erase_node(rx_list_t *self, rx_list_node_t *node);

RavenAPI rx_list_node_t* rx_list_erase_range(rx_list_t *self, rx_list_node_t *first, rx_list_node_t *last);

RavenAPI rx_list_node_t* rx_list_insert(rx_list_t *self, rx_list_node_t *pos, const void *data);


RavenAPI rx_list_node_t* rx_list_index(rx_list_t *self, size_t idx);

RavenAPI void*			rx_list_at(rx_list_t *self, size_t idx);

RavenAPI size_t			rx_list_size(const rx_list_t *self);

RavenAPI rx_bool		rx_list_is_empty(const rx_list_t *self);

RavenAPI void			rx_list_reverse(rx_list_t *self);

RavenAPI void			rx_list_splice_range(rx_list_t *self, rx_list_node_t *pos, rx_list_t *sour, rx_list_node_t *first, rx_list_node_t *last);

RavenAPI void			rx_list_merge(rx_list_t *self, rx_list_t *other);

RavenAPI void			rx_list_unique(rx_list_t *self);

RavenAPI size_t			rx_list_remove(rx_list_t *self, const void *data);

RavenAPI void			rx_list_sort(rx_list_t *self);

RavenAPI void			rx_list_swap(rx_list_t *self, rx_list_t *other);



/*
		rx_list_insert_args(list, "aaa","bbb","ccc","ddd", "eee", NULL);
*/
RavenAPI size_t rx_list_insert_args(rx_list_t *self, const void *data, ...);

/*
		rx_list_insert_args(list, 5, "aaa","bbb","ccc","ddd", "eee");
*/
RavenAPI size_t rx_list_insert_args_count(rx_list_t *self, size_t count, const void *data, ...);



RavenAPI void			rx_list_push_back(rx_list_t *self, const void *data);
RavenAPI void			rx_list_push_front(rx_list_t *self, const void *data);

RavenAPI void			rx_list_pop_back(rx_list_t *self);
RavenAPI void			rx_list_pop_front(rx_list_t *self);


RavenAPI rx_list_node_t* rx_list_find_pos(rx_list_t *self, rx_list_node_t *start, rx_list_node_t *end, const void *key);

#define rx_list_find(self, key) (rx_list_find_pos(self, NULL, NULL, key))


RavenAPI size_t rx_list_erase_equal(rx_list_t *self, const void *key);


RavenAPI size_t			rx_list_insert_range(rx_list_t *self, rx_list_node_t *pos, rx_list_t *sour, rx_list_node_t *start, rx_list_node_t *end);



#define rx_list_insert_range_end(self, s, b, e) rx_list_insert_range(self, NULL, s, b, e)
#define rx_list_insert_range_front(self, s, b, e) rx_list_insert_range(self, rx_list_head(self), s, b, e)



RX_SPACE_END


#endif

